package com.szrt.java.book.service;

import java.util.ArrayList;
import java.util.List;
import org.dom4j.Element;
import com.szrt.java.book.entity.BookEntity;
public class BookService {
	
	/**
	 * 插入1个节点 
	 * @param book
	 * @param root
	 */
	public void insertNode(BookEntity book,Element root){
		Element book01 = root.addElement("book");
		book01.addAttribute("id", ""+book.getId());
		Element bookName01 = book01.addElement("bookName");
		bookName01.setText(book.getBookName());
		Element author01 = book01.addElement("author");
		author01.setText(book.getAuthor());
		Element price01 = book01.addElement("price");
		price01.setText(""+book.getPrice());
	}
	
	
	
	/**
	 * 模仿拿到数据库中的所有的书
	 * @return
	 */
	public List<BookEntity> getBooks(){
		List<BookEntity> bookList = new ArrayList<BookEntity>();
		
		
		BookEntity book05 = new BookEntity();
		book05.setId(1005);
		book05.setBookName("倚天屠龙记");
		book05.setAuthor("金庸");
		book05.setPrice(500);
		book05.setPeriod("民国");
		
		BookEntity book04 = new BookEntity();
		book04.setId(1004);
		book04.setBookName("红楼梦");
		book04.setAuthor("曹雪芹");
		book04.setPrice(400);
		book04.setPeriod("清朝");
		
		BookEntity book03 = new BookEntity();
		book03.setId(1003);
		book03.setBookName("三国演义");
		book03.setAuthor("罗贯中");
		book03.setPrice(300);
		book03.setPeriod("元末明初");
		
		BookEntity book02 = new BookEntity();
		book02.setId(1002);
		book02.setBookName("水浒传");
		book02.setAuthor("施耐庵");
		book02.setPrice(200);
		book02.setPeriod("元末明初");
		
		BookEntity book01 = new BookEntity();
		book01.setId(1001);
		book01.setBookName("西游记");
		book01.setAuthor("吴承恩");
		book01.setPrice(100);
		book01.setPeriod("明朝");
		
		
		bookList.add(book01);
		bookList.add(book02);
		bookList.add(book03);
		bookList.add(book04);
		bookList.add(book05);
		return bookList;
	}
}
